package com.cy.jt.config;

import com.cy.jt.config.authentication.RedirectAuthenticationFailureSuccessHandler;
import com.cy.jt.config.authentication.RedirectAuthenticationSuccessHandler;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;

@Configuration
public class SecurityConfig extends WebSecurityConfigurerAdapter {
    @Bean
    public BCryptPasswordEncoder passwordEncoder(){
        return new BCryptPasswordEncoder();
    }
    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.csrf().disable();
        http.formLogin()
                .loginPage("/login.html")
                .loginProcessingUrl("/login")
                .usernameParameter("username")
                .passwordParameter("password")
                .successHandler(new RedirectAuthenticationSuccessHandler("http://localhost:63342/720zuoye/static/login.html?_ijt=95r624bgi49df7f88m31muig1s"));
                //.failureHandler(new RedirectAuthenticationFailureSuccessHandler("http://localhost:63342/720zuoye/static/login.html?_ijt=95r624bgi49df7f88m31muig1s"));
        http.authorizeRequests()
                .antMatchers("/login.html").permitAll()
                .anyRequest().authenticated();
}
}
